package
{
	import laya.device.motion.Gyroscope;
	import laya.device.motion.RotationInfo;
	import laya.display.Stage;
	import laya.display.Text;
	import laya.events.Event;

	public class Gyroscope_Sample
	{
		private var info:Text;
		public function Gyroscope_Sample()
		{
			info = new Text();
			info.fontSize = 20;
			info.color = "#ff0000";
			info.size(Laya.stage.width, Laya.stage.height);
			Laya.stage.addChild(info);
			Gyroscope.instance.on(Event.CHANGE, this, onDeviceorientation);
		}
		private function onDeviceorientation(absolute:Boolean, rotationInfo:RotationInfo):void 
		{
			Laya.stage.scaleMode = Stage.SCALE_FIXED_AUTO;
			if(Math.abs(rotationInfo.beta)<=12)
			{
				//横屏
				//Laya.stage.scaleMode = Stage.SCALE_FIXED_WIDTH;
				Laya.stage.screenMode = Stage.SCREEN_HORIZONTAL;
			}else
			{
				//竖屏
				//Laya.stage.scaleMode = Stage.SCALE_FIXED_HEIGHT;
				Laya.stage.screenMode = Stage.SCREEN_VERTICAL;
			}
			info.text = 
				"z [0, 360] alpha:" + Math.floor(rotationInfo.alpha) + '\n' +
				"x [-180, 180] beta :" + Math.floor(rotationInfo.beta) + '\n' +
				"y [-90, 90] gamma:" + Math.floor(rotationInfo.gamma)+"\n"+
				"screenMode:"+Laya.stage.screenMode;
		}
	}
}